$(function(){
    function openPage() {
        var obj = $(this);
        var url = obj.attr('dhref');
        var title = obj.attr('title');
        layer.open({
            type: 2,
            title: title,
            shadeClose: false,
            closeBtn:2,
            shade: 0.8,
            maxmin: true, //开启最大化最小化按钮
            area: ['75%', '740px'],
            content: url
        });
    }

    $(document).ready(function(){
        var $inc_count = $('.dec_num')
        $inc_count.on('keyup', function () {
            for(var i=0;i<$inc_count.length;i++){
                var  str =  $inc_count[i].value
                if(i==0){
                    if (str == ''){
                       var str1 =0
                    }
                    else {
                         str1 =str
                    }
                }
                if(i==1){
                    if (str == ''){
                        var str2 =0
                    }
                    else {
                         str2 =str
                    }
                }
                if(i==2){
                    if (str == ''){
                        var str3 =0
                    }
                    else {
                         str3 =str
                    }
                }
                if(i==3){
                    if (str == ''){
                        var str4 =0
                    }
                    else {
                         str4 =str
                    }
                }
                if(i==4){
                    if (str == ''){
                       var  str5 =0
                    }
                    else {
                         str5 =str
                    }
                }
                if(i==5){
                    if (str == ''){
                        var str6 =0
                    }
                    else {
                         str6 =str
                    }
                }
                if(i==6){
                    if (str == ''){
                        var str7 =0
                    }
                    else {
                        str7 =str
                    }
                }
                var net1=str1;
                var net2=str2;
                var net3=str3;
                var net4=str4;
                var net5=str5;
                var net6=str6;
                var net7=str7;
                if (!isNaN(net1)){
                    var cet1 =net1
                }
                else {
                    cet1 = 0
                }
                if (!isNaN(net2)){
                    var cet2 =net2
                }
                else {
                     cet2 = 0
                }
                if (!isNaN(net3)){
                     cet3 =net3
                }
                else {
                    var cet3 = 0
                }
                if (!isNaN(net4)){
                    var cet4 =net4
                }
                else {
                     cet4 = 0
                }
                if (!isNaN(net5)){
                    var cet5 =net5
                }
                else {
                     cet5 = 0
                }
                if (!isNaN(net6)){
                    var cet6 =net6
                }
                else {
                     cet6 = 0
                }
                if (!isNaN(net7)){
                    var cet7 =net7
                }
                else {
                     cet7 = 0
                }
                var stn = parseInt(cet1)+parseInt(cet2)+parseInt(cet3)+parseInt(cet4)+parseInt(cet5)+parseInt(cet6)+parseInt(cet7)
                if(!isNaN(stn)){
                    document.getElementById("red").innerHTML=stn+"件"
                }else{
                    document.getElementById("red").innerHTML="0件"
                }
            }
        });
    })
    $('.repertory_list').on('click', openPage); 
    //扫码枪出库
    $('.code').keydown(function(e){
    	var curKey = e.which;
    	if(curKey==13){
    		var $code = $('.code').val();
        	$.ajax({
                type:'POST',
                dataType:'json',
                url:'/business/repertory/barcodetemp',
                data:{code:$code},
                success:function (data){
                    if(data.state==1){
                    	window.location = '/business/goodsdec/repertoryout';
                    }else{
                    	layer.alert(data.message, {icon: 5});
                    }
                }
            })
    	}
    	
    });
    //保存出库数量
    $('.dec_num').blur(function(){
    	var $id = $(this).parent().parent().find('#rid').val();
    	var $num = $(this).val();
    	$.ajax({
            type:'POST',
            dataType:'json',
            url:'/business/repertory/tempnum',
            data:{id:$id,num:$num},
            success:function (data){
                if(data.state==0){
                	layer.alert(data.message, {icon: 5});
                }
            }
        })
    });
})